//
//  Int+ZJ.swift
//  ZJSwiftKit
//
//  Created by 万孟超 on 2023/3/8.
//

import Foundation

extension Int: ZJPrefixProtocol { }

// MARK: - Properties-
extension ZJPrefix where Base == Int {
    
    /// Int转换为String字符串
    public var toString: String {
        "\(base)"
    }
    
    // MARK: - 字体相关 -
    /// Int转换成系统字体
    public var systemFont: UIFont {
        UIFont.systemFont(ofSize: CGFloat(base))
    }
    
    /// Int转换为小粗字
    public var semiboldFont: UIFont {
        UIFont.systemFont(ofSize: CGFloat(base), weight: .semibold)
    }
    
    /// Int转换为中等粗字
    public var mediumFont: UIFont {
        UIFont.systemFont(ofSize: CGFloat(base), weight: .medium)
    }
    
    /// Int转换为中等粗字
    public var blodFont: UIFont {
        UIFont.systemFont(ofSize: CGFloat(base), weight: .bold)
    }
}


extension ZJPrefix where Base == Int {
    
    /// 自定义字体类型
   public enum ZJPrefixIntToCustomFontNameType {
       case CustomName(String)
       case PingFangSC(ZJPrefixIntToCustomFontNameWeightType)
       case Helvetica
       case HelveticaNeue(ZJPrefixIntToCustomFontNameWeightType)
       case Avenir(ZJPrefixIntToCustomFontNameWeightType)
        
       public enum ZJPrefixIntToCustomFontNameWeightType {
           case none
           case custom(String)
           case regular
           case medium
           case blod
           case semibold
           
           func weightName() -> String {
               switch self {
               case .none:
                   return ""
               case .regular:
                   return "-Regular"
               case .medium:
                   return "-Medium"
               case .blod:
                   return "-Blod"
               case .semibold:
                   return "-Semibold"
               case .custom(let weightString):
                   return "-" + weightString
               }
           }
       }
       
        /// 字体名称
        /// - Returns: 字体名称
        func fontName() -> String {
            switch self {
            case .CustomName(let fontName):
                return fontName
            case .PingFangSC(let weight):
                return "PingFangSC" + weight.weightName()
            case .Helvetica:
                return "Helvetica"
            case .HelveticaNeue(let weight):
                return "HelveticaNeue" + weight.weightName()
            case .Avenir(let weight):
                return "Avenir" + weight.weightName()
            }
        }
    }
    
    /// 自定义字体
    /// - Parameter fontName: 字体类型
    /// - Returns: 字体，可能为nil
    public func customFont(with fontName: ZJPrefixIntToCustomFontNameType) -> UIFont? {
        let font = fontName.fontName()
        return UIFont(name: font, size: CGFloat(base))
    }
}


// MARK: - 其他操作 -

extension ZJPrefix where Base == Int {
    
    /// 循环
    /// - Parameter block: 循环任务
    public func repeatTime(_ block: (Int, inout Bool)->()) {
        var stop = false
        for i in 0..<base {
            block(i, &stop)
            if stop {
                break
            }
        }
    }
}
